<?php
/**
 * 类名称
 * User: 13651
 * Time: 2025/9/25 15:36
 */

namespace App\Repository;

use App\Models\LeshuaUnionImg;

class LeshuaUnionImgRepo  extends CommonRepo
{

    /**
     * 根据商户id获取信息
     * @param int $storeId
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
     */
    public function getByStoreId(string $storeId)
    {
        return LeshuaUnionImg::query()->where('store_id',$storeId)->first();
    }

    /**
     * 保存图片数据
     * @param array $data
     * @param int $id
     * @return \Illuminate\Support\HigherOrderCollectionProxy|int|mixed
     */
    public function saveData(array $data,int $id =0)
    {
        if ($id) {
            $result  = LeshuaUnionImg::query()->find($id);
        } else {
            $result = new LeshuaUnionImg();
        }
        if (empty($result))
            return 0;
        collect($data)->map(function ($val, $field) use ($result) {
            $result->{$field} = $val;
        });
        return $result->save() ? $result->id : 0;
    }
}